/* 
 * Copyright (C) 2012 Martin Řehánek <rehan at mzk.cz>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

goog.provide('kramerius.audio.ui.VolumeButton');

goog.require('kramerius.audio.ui.Button');
goog.require('kramerius.audio.debug_utils');
goog.require('kramerius.audio.PlayerMock');
goog.require('goog.ui.Component');
goog.require('goog.ui.Control');

/** @const */ var VOLUME_ENABLED = 'btnVolumeEnabled';
/** @const */ var VOLUME_DISABLED = 'btnVolumeDisabled';

/**
 * @constructor 
 * @param {Element} container Element containing this button.
 * @param {kramerius.audio.Controller} controller Controller of the audio player.
 */
kramerius.audio.ui.VolumeButton =  function(container, controller){
    kramerius.audio.ui.Button.call(this, container, controller);
    this.controller_.setVolumeButton(this);
    /** @private */
    this.btnControl_ = this.initializeControl_();
    this.setEnabledImage();
};
goog.inherits(kramerius.audio.ui.VolumeButton, kramerius.audio.ui.Button);


/** @private */
kramerius.audio.ui.VolumeButton.prototype.initializeControl_ = function(){
    var btnControl = new goog.ui.Control();
    btnControl.setDispatchTransitionEvents(goog.ui.Component.State.ACTION, true);
    var playerController = this.controller_;
    var button = this;
    goog.events.listen(btnControl, goog.ui.Component.EventType.ACTION,
        function (e) {
            switch (button.getContainerClass_()){
                case VOLUME_ENABLED:
                    console.log("VolumeButton: muting");
                    playerController.mute();
                    break;
                case VOLUME_DISABLED:
                    console.log("VolumeButton: unmuting");
                    playerController.unMute();
                    break;
            }
        });
    //  kramerius.audio.utils.appendDebugListeners(button, "play button");
    btnControl.decorate(this.container_);
    return btnControl;
};


kramerius.audio.ui.VolumeButton.prototype.setEnabledImage = function(){
    this.setContainerClass_(VOLUME_ENABLED);
};


kramerius.audio.ui.VolumeButton.prototype.setDisabledImage = function(){
    this.setContainerClass_(VOLUME_DISABLED);
};

